package net.bitdixit.ywu.library;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;

import android.content.Context;
import android.content.res.AssetManager;

public class AsanaLibrary 
{
	public static String LANG_SK = "sk";
	public static String LANG_EN = "en";	
	
	public static String ASANA_DIR = "library/asana";
	private AssetManager assetManager;
	private Asana[]  allAsanas;
	private Context  context;
	
	public AsanaLibrary(Context context)
	{
		this.context = context;
		assetManager = context.getResources().getAssets();
		try { load(); } catch (Exception forget) {}
	} 
	
	public Asana[] getAllAsanas()
	{
		return allAsanas;
	}
	
	public static String getLangDescription(String lang)
	{
		if (lang.equals(LANG_SK)) return "sanskrit";
		else if (lang.equals(LANG_EN)) return "english";
		return null;
	}
	
	public Context getContext()
	{
		return context;
	}
	
	private void load() throws Exception
	{
		ArrayList<Asana> list = new ArrayList<Asana>();
		InputStream is = assetManager.open("library/dharmayoga.ananas");
		Properties prop =new Properties();
		prop.load(is);
		String ids = prop.getProperty("ids");
		for (String id : ids.split(","))
		{
			String name = prop.getProperty(id+".name");
			String name_eng = prop.getProperty(id+".name_eng");
			String img = prop.getProperty(id+".img");
			list.add(new Asana(this,id,name,name_eng,img));			
		}
		allAsanas=list.toArray(new Asana[list.size()]);
		Arrays.sort(allAsanas);
	}
}
